package com.tancire.question.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.tancire.question.domain.QuestionTree;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.question.domain.QuestionSector;
import com.tancire.question.service.IQuestionSectorService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 面试岗位Controller
 *
 * @author tancire
 * @date 2024-06-07
 */
@RestController
@RequestMapping("/question/questionSector")
public class QuestionSectorController extends BaseController {
    @Resource
    private IQuestionSectorService questionSectorService;

    /**
     * 查询面试岗位列表
     */
    @PreAuthorize("@ss.hasPermi('question:questionSector:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuestionSector questionSector) {
        startPage();
        List<QuestionSector> list = questionSectorService.selectQuestionSectorList(questionSector);
        return getDataTable(list);
    }

    /**
     * 导出面试岗位列表
     */
    @PreAuthorize("@ss.hasPermi('question:questionSector:export')")
    @Log(title = "面试岗位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuestionSector questionSector) {
        List<QuestionSector> list = questionSectorService.selectQuestionSectorList(questionSector);
        ExcelUtil<QuestionSector> util = new ExcelUtil<QuestionSector>(QuestionSector.class);
        util.exportExcel(response, list, "面试岗位数据");
    }

    /**
     * 获取面试岗位详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:questionSector:query')")
    @GetMapping(value = "/{sectorId}")
    public AjaxResult getInfo(@PathVariable("sectorId") Long sectorId) {
        return AjaxResult.success(questionSectorService.selectQuestionSectorBySectorId(sectorId));
    }

    /**
     * 新增面试岗位
     */
    @PreAuthorize("@ss.hasPermi('question:questionSector:add')")
    @Log(title = "面试岗位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionSector questionSector) {
        return toAjax(questionSectorService.insertQuestionSector(questionSector));
    }

    /**
     * 修改面试岗位
     */
    @PreAuthorize("@ss.hasPermi('question:questionSector:edit')")
    @Log(title = "面试岗位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionSector questionSector) {
        return toAjax(questionSectorService.updateQuestionSector(questionSector));
    }

    /**
     * 删除面试岗位
     */
    @PreAuthorize("@ss.hasPermi('question:questionSector:remove')")
    @Log(title = "面试岗位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sectorIds}")
    public AjaxResult remove(@PathVariable Long[] sectorIds) {
        return toAjax(questionSectorService.deleteQuestionSectorBySectorIds(sectorIds));
    }

    /**
     * 查询面试岗位树
     */
    @PreAuthorize("@ss.hasPermi('question:questionSector:list')")
    @GetMapping("/question/tree")
    public AjaxResult listTree() {
        List<QuestionTree> list = questionSectorService.selectQuestionSectorTree();
        return AjaxResult.success(list);
    }
}
